home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
SGI Developer Toolbox 6.1
/
SGI Developer Toolbox 6.1 - Disc 4.iso
/
public
/
Xprof
/
xmeasure
/
tstcolor.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-08-01
|
10KB
|
479 lines
/*==================================================================
* File : tstcolor.c
* Package: Xmeasure
*
* Author : Aloke Gupta.
*
* (C) Copyright 1992, Aloke Gupta.
* All rights granted to University of Illinois Board of Regents.
*==================================================================*/
#include "perf.h"
#define MAX_PLANES 1
#define NUMCOLORS 8
/* Shared variables */
static XColor xcolors[NUMCOLORS];
static unsigned int *plane_masks;
static unsigned int pmask;
static unsigned long *pixels;
static char *cname = "red";
static Colormap *colormaps;
static Colormap **cmaplist; /* array of pointers to Colormap */
static int i;
/* ====================================================================== */
int CreateColormap(xd, xp)
XD *xd;
XParams *xp;
{
for (i = 0; i < xp->itns; i++) {
colormaps[i] = XCreateColormap(xd->display, xd->window,
xd->visual, AllocNone);
if (!colormaps[i]) {
xp->itns = i;
fprintf(stderr,"# CreateColormap: Can only create %d colormaps out of %d\n",
i , xp->itns);
return;
}
}
}
int i_CreateColormap(xd, xp)
XD *xd;
XParams *xp;
{ colormaps = (Colormap *) calloc (xp->itns, sizeof (Colormap)); }
int c_CreateColormap(xd, xp)
XD *xd;
XParams *xp;
{
for (i = 0; i < xp->itns; i++)
XFreeColormap(xd->display, colormaps[i]);
free(colormaps);
}
/* ====================================================================== */
int FreeColormap(xd, xp)
XD *xd;
XParams *xp;
{
for (i = 0; i < xp->itns; i++)
XFreeColormap(xd->display, colormaps[i]);
}
int i_FreeColormap(xd, xp)
XD *xd;
XParams *xp;
{
colormaps = (Colormap *) calloc (xp->itns, sizeof (Colormap));
for (i = 0; i < xp->itns; i++) {
colormaps[i] = XCreateColormap(xd->display, xd->window,
xd->visual, AllocNone);
if (!colormaps[i]) {
xp->itns = i;
fprintf(stderr,"# FreeColormap: Can only create %d colormaps out of %d\n",
i , xp->itns);
return;
}
}
}
int c_FreeColormap(xd, xp)
XD *xd;
XParams *xp;
{ free(colormaps); }
/* ====================================================================== */
int CopyColormapAndFree(xd, xp)
XD *xd;
XParams *xp;
{
for (i = 0; i < xp->itns; i++) {
colormaps[i] = XCopyColormapAndFree(xd->display, xd->cmap);
if (!colormaps[i]) {
xp->itns = i;
fprintf(stderr,"# CopyColormapAndFree: Can only create %d colormaps out of %d\n",
i , xp->itns);
return;
}
}
}
int i_CopyColormapAndFree(xd, xp)
XD *xd;
XParams *xp;
{ colormaps = (Colormap *) calloc (xp->itns, sizeof (Colormap)); }
int c_CopyColormapAndFree(xd, xp)
XD *xd;
XParams *xp;
{
for (i = 0; i < xp->itns; i++)
XFreeColormap(xd->display, colormaps[i]);
free(colormaps);
}
/* ====================================================================== */
int InstallColormap(xd, xp)
XD *xd;
XParams *xp;
{
for (i = 0; i < xp->itns; i++) {
if (!XInstallColormap(xd->display, xd->cmap)) {
fprintf(stderr, "# InstallColormap: Cannot install %dth colormap\n",
i);
xp->itns=i;
return ;
}
}
}
int i_InstallColormap(xd, xp)
XD *xd;
XParams *xp;
{ }
int c_InstallColormap(xd, xp)
XD *xd;
XParams *xp;
{ }
/* ====================================================================== */
int UninstallColormap(xd, xp)
XD *xd;
XParams *xp;
{
for (i = 0; i < xp->itns; i++)
XUninstallColormap(xd->display, xd->cmap);
}
int i_UninstallColormap(xd, xp)
XD *xd;
XParams *xp;
{ }
int c_UninstallColormap(xd, xp)
XD *xd;
XParams *xp;
{ }
/* ====================================================================== */
int ListInstalledColormaps(xd, xp)
XD *xd;
XParams *xp;
{
int num;
for (i = 0; i < xp->itns; i++)
cmaplist[i] = XListInstalledColormaps(xd->display, xd->window, &num);
}
int i_ListInstalledColormaps(xd, xp)
XD *xd;
XParams *xp;
{
cmaplist = (Colormap **) calloc (xp->itns, sizeof (Colormap *));
}
int c_ListInstalledColormaps(xd, xp)
XD *xd;
XParams *xp;
{
for (i = 0; i < xp->itns; i++)
XFree((caddr_t) cmaplist[i]);
free(cmaplist);
}
/* ====================================================================== */
int AllocColor(xd, xp)
XD *xd;
XParams *xp;
{
for (i = 0; i < xp->itns; i++){
if (!XAllocColor(xd->display, xd->cmap, &xcolors[0])) {
fprintf(stderr,"# AllocColor: Cannot allocate %dth color\n", i);
}
}
}
int i_AllocColor(xd, xp)
XD *xd;
XParams *xp;
{
XParseColor(xd->display, xd->cmap, cname, &xcolors[0]);
}
int c_AllocColor(xd, xp)
XD *xd;
XParams *xp;
{ }
/* ====================================================================== */
int AllocNamedColor(xd, xp)
XD *xd;
XParams *xp;
{
for (i = 0; i < xp->itns; i++) {
if (!XAllocNamedColor(xd->display,xd->cmap,cname,&xcolors[0],&xcolors[1]))
fprintf(stderr,"#AllocNamedColor: Cannot allocate %dth color\n",i);
}
}
int i_AllocNamedColor(xd, xp)
XD *xd;
XParams *xp;
{ }
int c_AllocNamedColor(xd, xp)
XD *xd;
XParams *xp;
{ }
/* ====================================================================== */
int AllocColorCells(xd, xp)
XD *xd;
XParams *xp;
{
for (i = 0; i < xp->itns; i++) {
if (!XAllocColorCells(xd->display, xd->cmap, False,
plane_masks + (i * MAX_PLANES), MAX_PLANES,
pixels + (i * NUMCOLORS ), NUMCOLORS)) {
/*
fprintf(stderr,
"\n# AllocColorCells: Cannot allocate %d cells for the %d itn\n",
NUMCOLORS, i);
fflush(stderr);
*/
xp->itns = i;
return;
}
}
}
int i_AllocColorCells(xd, xp)
XD *xd;
XParams *xp;
{
plane_masks = (unsigned *) calloc(MAX_PLANES * xp->itns,
sizeof(unsigned));
pixels = (unsigned long *) calloc(NUMCOLORS * xp->itns,
sizeof(unsigned long));
}
int c_AllocColorCells(xd, xp)
XD *xd;
XParams *xp;
{
pmask=0;
if (xp->itns > 0)
for (i=0; i <MAX_PLANES; i++)
pmask |= plane_masks[i];
for (i = 0; i < xp->itns; i++) {
XFreeColors(xd->display, xd->cmap,
pixels + (i * NUMCOLORS), NUMCOLORS,
pmask);
}
free(plane_masks);
free(pixels);
}
/* ====================================================================== */
int AllocColorPlanes(xd, xp)
XD *xd;
XParams *xp;
{
}
int i_AllocColorPlanes(xd, xp)
XD *xd;
XParams *xp;
{
}
int c_AllocColorPlanes(xd, xp)
XD *xd;
XParams *xp;
{
}
/* ====================================================================== */
int FreeColors(xd, xp)
XD *xd;
XParams *xp;
{
for (i = 0; i < xp->itns; i++)
XFreeColors(xd->display,xd->cmap,pixels+(i*NUMCOLORS),NUMCOLORS,pmask);
}
int i_FreeColors(xd, xp)
XD *xd;
XParams *xp;
{
plane_masks = (unsigned *) calloc(MAX_PLANES*xp->itns,sizeof(unsigned));
pixels = (unsigned long *) calloc(NUMCOLORS*xp->itns,sizeof(unsigned));
for (i = 0; i < xp->itns; i++) {
if (!XAllocColorCells(xd->display, xd->cmap, False,
plane_masks + (i * MAX_PLANES), MAX_PLANES,
pixels + (i * NUMCOLORS ), NUMCOLORS)) {
xp->itns = i;
return;
}
}
pmask=0;
for (i=0; i <MAX_PLANES; i++)
pmask |= plane_masks[i];
}
int c_FreeColors(xd, xp)
XD *xd;
XParams *xp;
{
free(plane_masks);
free(pixels);
}
/* ====================================================================== */
int StoreColors(xd, xp)
XD *xd;
XParams *xp;
{
for (i = 0; i < xp->itns; i++)
XStoreColors(xd->display, xd->cmap, xcolors, NUMCOLORS);
}
int i_StoreColors(xd, xp)
XD *xd;
XParams *xp;
{
plane_masks = (unsigned *) calloc(MAX_PLANES, sizeof(unsigned));
pixels = (unsigned long *) calloc(NUMCOLORS, sizeof(unsigned));
if (!XAllocColorCells(xd->display, xd->cmap, False, plane_masks,
MAX_PLANES, pixels, NUMCOLORS)) {
fprintf(stderr,"\n# StoreColors: Cannot allocate %d cells to test\n",
NUMCOLORS); fflush(stderr);
xp->itns = 0;
return;
}
for (i = 0; i < NUMCOLORS; i++) {
XParseColor(xd->display, xd->cmap, cname, &xcolors[i]);
xcolors[i].pixel = pixels[i];
}
}
int c_StoreColors(xd, xp)
XD *xd;
XParams *xp;
{
pmask=0;
for (i=0; i < MAX_PLANES; i++)
pmask |= plane_masks[i];
if (xp->itns !=0)
XFreeColors(xd->display, xd->cmap, pixels, NUMCOLORS, pmask);
free(plane_masks);
free(pixels);
}
/* ====================================================================== */
int StoreNamedColor(xd, xp)
XD *xd;
XParams *xp;
{
for (i = 0; i < xp->itns; i++)
XStoreNamedColor(xd->display, xd->cmap, cname,
pixels[0], DoRed | DoGreen| DoBlue);
}
int i_StoreNamedColor(xd, xp)
XD *xd;
XParams *xp;
{
plane_masks = (unsigned *) calloc(MAX_PLANES, sizeof(unsigned));
pixels = (unsigned long *) calloc(NUMCOLORS , sizeof(unsigned));
if (!XAllocColorCells(xd->display, xd->cmap, False, plane_masks,
MAX_PLANES, pixels, 1)) {
fprintf(stderr,"\n# StoreNamedColor: Cannot allocate 1 cell to test\n");
fflush(stderr);
xp->itns = 0;
return;
}
}
int c_StoreNamedColor(xd, xp)
XD *xd;
XParams *xp;
{
pmask=0;
for (i=0; i < MAX_PLANES; i++)
pmask |= plane_masks[i];
if (xp->itns !=0)
XFreeColors(xd->display, xd->cmap, pixels, 1, pmask);
free(plane_masks);
free(pixels);
}
/* ====================================================================== */
int QueryColors(xd, xp)
XD *xd;
XParams *xp;
{
for (i = 0; i < xp->itns; i++)
XQueryColors(xd->display, xd->cmap, xcolors, NUMCOLORS);
}
int i_QueryColors(xd, xp)
XD *xd;
XParams *xp;
{
for (i = 0; i < NUMCOLORS; i++)
xcolors[i].pixel = BlackPixel(xd->display, xd->screen);
}
int c_QueryColors(xd, xp)
XD *xd;
XParams *xp;
{ }
/* ====================================================================== */
int LookupColor(xd, xp)
XD *xd;
XParams *xp;
{
for (i = 0; i < xp->itns; i++)
XLookupColor(xd->display, xd->cmap, cname, &xcolors[0], &xcolors[1]);
}
int i_LookupColor(xd, xp)
XD *xd;
XParams *xp;
{ }
int c_LookupColor(xd, xp)
XD *xd;
XParams *xp;
{ }
/* ====================================================================== */